namespace Mondial2014.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class InitialCreate : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.Fixtures",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Number = c.Int(nullable: false),
                        Date = c.DateTime(nullable: false),
                        Team1Score = c.Int(nullable: false),
                        Team2Score = c.Int(nullable: false),
                        Discriminator = c.String(nullable: false, maxLength: 128),
                        Stage_Id = c.Int(),
                        Team1_Id = c.Int(),
                        Team2_Id = c.Int(),
                        Group_Id = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Stages", t => t.Stage_Id)
                .ForeignKey("dbo.Teams", t => t.Team1_Id)
                .ForeignKey("dbo.Teams", t => t.Team2_Id)
                .ForeignKey("dbo.Groups", t => t.Group_Id)
                .Index(t => t.Stage_Id)
                .Index(t => t.Team1_Id)
                .Index(t => t.Team2_Id)
                .Index(t => t.Group_Id);
            
            CreateTable(
                "dbo.Stages",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Level = c.Int(nullable: false),
                        Name = c.String(),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Teams",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(),
                        Group_Id = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Groups", t => t.Group_Id)
                .Index(t => t.Group_Id);
            
            CreateTable(
                "dbo.Groups",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Number = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Gamblers",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.GameGambles",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        GameGambleResult = c.Int(nullable: false),
                        Fixture_Id = c.Int(),
                        Gambler_Id = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Fixtures", t => t.Fixture_Id)
                .ForeignKey("dbo.Gamblers", t => t.Gambler_Id)
                .Index(t => t.Fixture_Id)
                .Index(t => t.Gambler_Id);
            
        }
        
        public override void Down()
        {
            DropForeignKey("dbo.GameGambles", "Gambler_Id", "dbo.Gamblers");
            DropForeignKey("dbo.GameGambles", "Fixture_Id", "dbo.Fixtures");
            DropForeignKey("dbo.Fixtures", "Group_Id", "dbo.Groups");
            DropForeignKey("dbo.Teams", "Group_Id", "dbo.Groups");
            DropForeignKey("dbo.Fixtures", "Team2_Id", "dbo.Teams");
            DropForeignKey("dbo.Fixtures", "Team1_Id", "dbo.Teams");
            DropForeignKey("dbo.Fixtures", "Stage_Id", "dbo.Stages");
            DropIndex("dbo.GameGambles", new[] { "Gambler_Id" });
            DropIndex("dbo.GameGambles", new[] { "Fixture_Id" });
            DropIndex("dbo.Teams", new[] { "Group_Id" });
            DropIndex("dbo.Fixtures", new[] { "Group_Id" });
            DropIndex("dbo.Fixtures", new[] { "Team2_Id" });
            DropIndex("dbo.Fixtures", new[] { "Team1_Id" });
            DropIndex("dbo.Fixtures", new[] { "Stage_Id" });
            DropTable("dbo.GameGambles");
            DropTable("dbo.Gamblers");
            DropTable("dbo.Groups");
            DropTable("dbo.Teams");
            DropTable("dbo.Stages");
            DropTable("dbo.Fixtures");
        }
    }
}
